package com.ibeeking.found.report.rest.config;

import com.ibeeking.found.report.rest.config.redis.ReportCacheHelper;
import com.ibeeking.found.report.rest.config.redis.CacheHelper;
import com.ibeeking.nematos.file.oss.config.OssProp;
import com.ibeeking.nematos.file.oss.ossbuilder.FileClientFactory;
import com.ibeeking.nematos.file.oss.ossbuilder.OssTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.cache.ehcache.EhCacheCache;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * business配置类
 * @author lr
 * @since 2021-04-08
 */
@Configuration
@MapperScan(basePackages = {"com.ibeeking.found.report.service.common.dos"})
public class ReportAutoConfiguration {

    @Resource
    private OssProp ossProp;

    public CacheHelper reportCacheHelper(){
        return new ReportCacheHelper();
    }

    @Bean
    @ConditionalOnMissingBean
    public OssTemplate ossTemplate()  throws Exception{
        FileClientFactory fileOpFactory = new FileClientFactory(ossProp);
        return fileOpFactory.getObject();
    }

    @Bean
    public EhCacheCache ehCacheCache() {
        return (EhCacheCache) ehCacheCacheManager().getCache("reportCache");
    }

    /**
     * 创建ehCacheCacheManager
     */
    @Bean
    public EhCacheCacheManager ehCacheCacheManager() {

        return new EhCacheCacheManager();
    }
}
